package io.renren.modules.usian.service.impl;

import io.renren.modules.usian.entity.CollegeEntity;
import io.renren.modules.usian.entity.TeacherEntity;
import io.renren.modules.usian.service.CollegeService;
import io.renren.modules.usian.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.usian.dao.ClassDao;
import io.renren.modules.usian.entity.ClassEntity;
import io.renren.modules.usian.service.ClassService;


@Service("classService")
public class ClassServiceImpl extends ServiceImpl<ClassDao, ClassEntity> implements ClassService {

    @Autowired
    private CollegeService collegeService;

    @Autowired
    private TeacherService teacherService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ClassEntity> page = this.page(
                new Query<ClassEntity>().getPage(params),
                new QueryWrapper<ClassEntity>()
        );

        List<ClassEntity> list = page.getRecords();
        list.stream().map((classs)->{
            CollegeEntity college = collegeService.getById(classs.getCid());
//            TeacherEntity teacher = teacherService.getById(classs.getTid());
//            TeacherEntity teacher1 = teacherService.getById(classs.getHid());
            classs.setCname(college.getName());
//            classs.setCname(teacher.getName());
//            classs.setCname(teacher1.getName());
            return classs;
        }).collect(Collectors.toList());


        return new PageUtils(page);
    }
}